/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package preka;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import prefuse.data.Graph;
import prefuse.data.io.DataIOException;
import prefuse.data.io.IVCArffReader;
import preka.prefuse.data.io.ArffReader;
import weka.clusterers.MPCKMeans;
import weka.clusterers.metriclearners.WEuclideanLearner;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.SelectedTag;
import weka.core.metrics.WeightedEuclidean;

/**
 *
 * @author vhbarros
 */

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws DataIOException, Exception {
        // Teste geração automática de informação relacional
        //IVC ivc = new IVC(IVC.MPCKMEANS, IVC.FORCE_DIRECTED, true);
        IVC ivc = new IVC();

        ivc.loadGraph("/home/vhbarros/Dropbox/Tese/Software/preka/data/teste.arff");
        ivc.generateRelationalData();
        
        
        /* Teste Ficheiros
        try {
            ArffReader r = new ArffReader("/home/vhbarros/Dropbox/Tese/Backup/Projects/wekaUT/weka-latest/data/iris.arff");

            MPCKMeans mpckmeans = new MPCKMeans();
            mpckmeans.setUseMultipleMetrics(false);

            WeightedEuclidean metric = new WeightedEuclidean();
            WEuclideanLearner metricLearner = new WEuclideanLearner();
            mpckmeans.setMetric(metric);
            mpckmeans.setMetricLearner(metricLearner);

            mpckmeans.setVerbose(false);
            mpckmeans.setRegularize(false);
            mpckmeans.setTrainable(new SelectedTag(MPCKMeans.TRAINING_INTERNAL, MPCKMeans.TAGS_TRAINING));
            mpckmeans.setSeedable(true);

            Instances data = r.getData();
            // Criar um novo conjunto para efectuar o clustering
            Instances clusterData = new Instances(data);
            clusterData.deleteClassAttribute();         // Para o clustering não vai o atributo da classe

            // Escrever restrições
            ArrayList constraints = new ArrayList();
            String[] c1 = {"1","122","-1"};
            String[] c2 = {"3","111","-1"};
            String[] c3 = {"5","18","1"};
            constraints.add(c1);
            constraints.add(c2);
            constraints.add(c3);

            r.writeArffConstraints("/home/vhbarros/Dropbox/Tese/Software/preka/data/teste.constraints", constraints);

            // Criar restrições a partir do ficheiro
            ArrayList labeledPair = mpckmeans.readConstraints("/home/vhbarros/Dropbox/Tese/Software/preka/data/teste.constraints");

            mpckmeans.buildClusterer(labeledPair, clusterData, data, data.numClasses(), data.numInstances());
            

            HashSet[] clusters = mpckmeans.getIndexClusters();
            int numClusters = mpckmeans.getNumClusters();
            //mpckmeans.printIndexClusters();

//            for (int i=0; i < mpckmeans.getNumClusters(); i++)
//            {
//                HashSet cluster = clusters[i];
//                Iterator iter = cluster.iterator();
//                while (iter.hasNext()) {
//                    int idx = ((Integer) iter.next()).intValue();
//                    Instance inst = data.instance(idx);
//                    if (data.classIndex() >= 0) {
//                            System.out.println("\t\t"
//                                            + idx
//                                            + ":"
//                                            + inst.classAttribute().value(
//                                                            (int) inst.classValue()));
//                    }
//                }
//            }
            
            //r.writeGraphML("/home/vhbarros/Dropbox/Tese/Software/preka/data/teste.xml", clusters, numClusters, null); // TODO mudar null!!
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }*/


    }

}
